<template>
  <div>
      <el-row style="padding:20px;margin-top:20px">
        <el-col :span="24">
          <el-steps :active="step" style="margin-left:20%;font-size:39px;cursor:pointer;">
                <el-step title="步骤 1" style="text-align:center" icon="edit" description="添加事件的的基本信息">
                </el-step>
                <el-step title="步骤 2" icon="upload" description="添加图片信息">
                </el-step>
            </el-steps>
        </el-col>
        <el-col v-if="step==1" :span="18" style="margin-top:30px;">
           <el-form :model="form" :rules="rules" ref="form" label-width="200px" label-suffix="：">
               <el-form-item v-for="(v,k,i) in form" :label="labels[i]" :key="v.id" :prop="k" v-if="k!='id'">
                    <el-select v-if="k=='vechiclesTypeValue'" v-model="form[k]">
                        <el-option v-for="vs in carType" :key="vs.vechiclesTypeValue" :value="vs.vechiclesTypeValue" :label="vs.vechiclesTypeName"></el-option>
                    </el-select>
                    <el-select v-else-if="k=='netGridID'" v-model="form[k]">
                        <el-option v-for="vg in netGridType" :key="vg.id" :value="vg.netGridID" :label="vg.netGridName"></el-option>
                    </el-select>
                    <el-input autosize v-else-if="k=='remarks'||k=='insuranceInf'||k=='yearCheckInf'" v-model="form[k]" type="textarea"></el-input>
                    <el-input style="width:300px" v-else v-model="form[k]"></el-input>
                </el-form-item>
                <el-form-item align="center">
                    <el-button type="warning">重置</el-button>
                    <el-button type="primary" @click="addNewRecord">添加</el-button>
                </el-form-item>
           </el-form>
        </el-col>
        <el-col v-else-if="step==2" style="margin-top:30px;" :span="18">
          <div style="margin-left:25%">
            <h4>图片上传（支持多图）</h4>
            <el-upload
              class="upload-demo"
              :action="getDomain()+'/msmis/api/key/uploadKeyVehiclesPictures?id='+form.id"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :file-list="fileList2"
              list-type="picture">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
          </div>
        </el-col>
        <el-col :span="24">
            <div class="preDiv">
                <i v-if="step!=1" class="fa fa-angle-double-left fa-5x" @click="goPre"></i>
                <div v-if="step!=1" class="directionFont"  @click="goPre">
                    上一步(继续添加信息)
                </div>
            </div>
            <div class="nextDiv">
                <i v-if="step!=2" class="fa fa-angle-double-right fa-5x" @click="goNext"></i>
                <div v-if="step!=2" class="directionFont" @click="goNext">
                    下一步(上传图片)
                </div>
                <i v-if="step==2" class="fa fa-history fa-5x" @click="submit"></i>
                <div v-if="step==2" class="directionFont" @click="submit">
                    完成
                </div>
            </div>
        </el-col>
      </el-row>
  </div>
</template>

<script>
import * as api from "@/api/videoManage"
import * as api2 from "@/api/trafficManage"

export default {
  data() {
    return {
      mytype: 2,
      flag: 0,
      step: 1,
      fileList2: [],
      dialogVisible: false,
      form: {
        id:'',
        vehiclesHolderCertID: "", //'车主身份证号',
        vehiclesHolderName: "", //'车主姓名',
        vechiclesNumber: "", //'车牌号码',
        vechiclesTypeValue: "", //'车辆类型编码，具体待确认。',
        insuranceInf: "", //'保险情况',
        enterpriseUSCcode: "", //'如果登记在企业内，则填入企业统一社会信用代码；如果是个人，该字段留空',
        yearCheckInf: "", //'年检情况',
        netGridID: 1, //'登记地或所属企业地的所在网格号。',
        contact: "", //'联系方式，电话等',
        remarks: "" //varchar(500),
      },
      labels: [
        '编号',
        "车主身份证号",
        "车主姓名",
        "车牌号码",
        "车辆类型",
        "保险情况",
        "统一社会信用代码",
        "年检情况",
        "所属网格",
        "联系方式",
        "备注"
      ],
      rules: {
        vehiclesHolderCertID: [
          { required: true, message: "身份证不得为空!", trigger: "blur" }
        ]
      },
      netGridType: [],
      carType:[]
    };
  },
  methods: {
    getDomain(){
      return 'http://' + window.location.host;
    },
    goPre() {
      this.flag = 0;
      if (this.step > 1) {
        this.step = this.step - 1;
      }
    },
    goNext() {
      // if (this.flag == 0 || this.form.keyDriverName == "") {
      //   this.$notify.error({
      //     title: "错误",
      //     message: "请先您保存基本信息，再添加图片信息！"
      //   });
      //   return;
      // }
      if (this.step < 2) {
        this.step = this.step + 1;
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    submit() {
      this.$router.go(-1);
    },
    addNewRecord() {
        api2.addKeyVehicles(this.form).then(res => {
          if (res.data) {
            this.$message({
              type: "success",
              message: "添加成功!"
            });
            this.form.id = res.data
          } else {
            this.$message({
              type: "error",
              message: res.message
            });
          }
        });
    }
  },
  mounted() {
    api.fetchNetGrid().then(res => {
      this.netGridType = res.data;
    });
    api2.fetchVechiclesCode().then(res=>{
      this.carType = res.data
    })
  }
};
</script>


<style scoped>
.preDiv {
  position: fixed;
  top: 300px;
  left: 10%;
  cursor: pointer;
  color: #58b7ff;
  text-align: center;
  /* margin-left: 10px; */
}
.nextDiv {
  position: fixed;
  top: 300px;
  right: 0;
  cursor: pointer;
  color: #58b7ff;
  text-align: center;
  margin-right: 10px;
}
</style>
